package com.winit.openapi.wh.outbound.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.outbound.OutboundSystemOrderTrackingService;
import com.winit.oms.spi.outbound.command.order.OutboundOrderFeeTestCommand;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.openapi.util.ValidateUtil;

/**
 * 这是一个测试用的controller,用于新老系统费用对比测试
 * 
 * @version <pre>
 * Author	Version		Date		Changes
 * bing.gu 	1.0  		2016年12月14日 	Created
 *
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/wh/outbound")
public class OutboundOrderFeeTestController extends BaseController {

    @Resource
    private OutboundSystemOrderTrackingService outboundSystemOrderTrackingService;

    /**
     * 产品查询
     * 
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/feeTest")
    public String getOrderWinitServiceByOrderNo(@ModelAttribute RequestMsg requestMsg,
                                                @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        OutboundOrderFeeTestCommand command = new OutboundOrderFeeTestCommand();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            ValidateUtil.validNotNull(json, "orderNo");
            ValidateUtil.validNotNull(json, "trackingCode");
            command.setOrderNo(json.getString("orderNo"));
            command.setTrackingCode(json.getString("trackingCode"));
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        // 调用接口插入轨迹,根据轨迹节点计算费用
        outboundSystemOrderTrackingService.feeTest(command);
        responseMsg.setMsg("SUCCESS");
        return SUCCESS;
    }

}
